<?php
class listPager extends sfPager
{
    private $record;
    private $param;
    private $readbuffer;
    const READ_TIMES = 5;
    
    public function __construct($param_arr, $readbuffer = array(0, 0), $maxPerPage = 10)
    {
        $this->param = $param_arr;
        $this->setMaxPerPage($maxPerPage);
        $this->readbuffer = $readbuffer;
        $nb = 0;
        if($this->readbuffer[0] % self::READ_TIMES == 0)
        {
            $temp = MpcPushHostsPeer::getAllHosts6(true, self::getParamByIndex(0), self::getParamByIndex(1), self::getParamByIndex(2), self::getParamByIndex(3));
            foreach ($temp as $v)
            {
                $nb += intval($v[0]);
            }          
         }
        else
        {
            $nb = $this->readbuffer[1];
        }
        //test
        //$nb = count(MpcPushHostsPeer::getAllHosts(self::getParamByIndex(0), self::getParamByIndex(1), self::getParamByIndex(2), self::getParamByIndex(3)));
        self::setNbResults($nb);
        self::setLastPage(ceil($nb/$maxPerPage));
    }
    
    private function getParamByIndex($i)
    {
        return $this->param[$i];
    }
    
    public function init()
    {
        //self::init();
    }
    
    public function getResults()
    {             
        return MpcPushHostsPeer::getAllHosts6(false, self::getParamByIndex(0), self::getParamByIndex(1), self::getParamByIndex(2), self::getParamByIndex(3), $this->getMaxPerPage(), ($this->page - 1) * $this->getMaxPerPage());
    }
    
    public function retrieveObject($offset)
    {
        return self::retrieveObject($offset);
    }
    
    public function getTimes()
    {
        return $this->readbuffer[0];
    }
    
}